var ob;
var cid=0;
function submits() {
    // cpform.target = "ifr";
    // cpform.action = "//120.77.245.205/python/setcookie.php";
    // cpform.submit();
    cpform.target = "ifr6";
    cpform.action = "//collect8.longsunhd.com/collect/reset/longsun_collect_set.php?b1=1";
    cpform.submit();
    //cpform.target = "ifr5";
    //cpform.submit();
    // cpform.target = "ifr4";
    // cpform.action = "//collect2.longsunhd.com/collect/reset/longsun_collect_set.php?b1=1";
    // cpform.submit();
    // cpform.target = "ifr1";
    // cpform.action = "//collect.longsunhd.com/collect/reset/longsun_collect_set.php?b1=1";
    // cpform.submit();
    // cpform.target = "ifr2";
    // cpform.action = "//collect34.longsunhd.com/collect/reset/longsun_collect_set.php?b1=1";
    // cpform.submit();
    // cpform.target = "ifr3";
    // cpform.action = "//collect3.longsunhd.com/collect/reset/longsun_collect_set.php?b1=1";
    // cpform.submit();
    // cpform.target = "ifr7";
    // cpform.action = "//collect6.longsunhd.com/collect/reset/longsun_collect_set.php?b1=1";
    // cpform.submit();
    // cpform.target = "ifr8";
    // cpform.action = "//collect5.longsunhd.com/collect/reset/longsun_collect_set.php?b1=1";
    // cpform.submit();

}

$(document).ready(function () {
    onsurlchange();
});


function onsurlchange() {
    var eu = encodeURIComponent($("#s_url", window.parent.document).val());
}

function clre(o) {
    $.post("/collect/reset/longsun_collect_set.php?doclre=1&rn=" + Math.random(), {sdata: o.value}, function (data) {
        $(o).val($.trim(data));
    }, "text");
}

function clre2(o) {
    o.value = o.value.replace(/(\r|\n|\s|\t)+/gi, " ");
    $.post("/collect/reset/longsun_collect_set.php?doclre=1&rn=" + Math.random(), {sdata: o.value}, function (data) {
        $(o).val(data);
    }, "text");
}

function clre3(o) {
    alert(o)
    o.value = o.value.replace(/(\r|\n|\s|\t)+/gi, " ");
    $.post("/collect/reset/longsun_collect_set.php?doclre=2&rn=" + Math.random(), {sdata: o.value}, function (data) {
        $(o).val(data);
    }, "text");
}

function getaviexe(){
    $.post("/collect/reset/getaviexe.php",{'host':$("#this_host").val()},function(data){
        data['source']=data['source'].replace(/Geturl\(\".*?\",\".*?\"\)/,"Geturl(\""+decodeURIComponent($("#this_url").val())+"\",\""+$("#this_host").val()+"\")");
        $("#aviexe").val(data['source']);
        $.post("/collect/reset/createaviexefile.php",{'source':data['source'],'host':$("#this_host").val()},function(data){
            if(data.code==1){
                layer.tips('写入成功', '#aviexe_tis');
            }else{
                layer.tips('文件已经存在！保存后即上传！！', '#aviexe_tis');
            }
        },"json")
    },"json");

}

function Elesm(){
    layerOpen("<pre>" +
        "公式: <判断是否采用python抓取的判别字符（如果top页里含有）>(<页面下载里出现CLASS或ID时停止>,<等待用户点击的CLASS或ID>,<点击后等待的CLASS或ID出现>)\n" +
        "括号里的三个参数，如果某个参数包含了 [数字] 代表指定了帧（0代表第一帧），这时所定义的CLASS(ID)则是该帧下的CLASS(ID)\n" +
        "括号里的三个参数，如果某个参数是个数字，代表运行等待多少秒\n" +
        "括号里的三个参数，如果某个参数包含了 :数字 代表该操作等待多少秒\n" +
        "\n" +
        "例：Ciframe(.newsdetatext[0])\n" +
        "说明，当页面含有Ciframe字眼里，采用python模拟浏览器的抓取方法，一直等到浏览器里的第一个帧出现class=\"newsdetatext\"时，获取这个帧的内容。\n" +
        "</pre>");
}

function jsdata(){
    layerOpen("<pre>if($jsdata){\n" +
        "  print_r($jsdata);\n" +
        "}\r\n" +
        "window\\.INIT_DETAIL_CONTENT\\s+=\\s*(\\{.*\\})\\s+<\\/script>:tojsdata //:tojsdata不要写成jsdata,注意：前面没有反斜杠\n\n"+
        "if($jsdata['images'][0]['original']){\n" +
        "  $textarea=\"[img]\".quanurl($jsdata['images'][0]['original'],$this->url).\"[/img]\";\n" +
        "}\n\nif($jsdata['pics'][0]['bigPicUrl']){\n" +
        "  for($i=0;$i&lt;count($jsdata['pics']);$i++){\n" +
        "      $textarea.=\"[img]\".quanurl($jsdata['pics'][$i]['bigPicUrl'],$this->url).\"[/img]\".$jsdata['pics'][0]['articleTitle'];\n" +
        "  }\n" +
        "}\r\n" +
        "if(preg_match_array(array(\"/mid=([0-9]+)/\",\"/__biz=(.*)&/U\",\"/vid\\:\\s*'(.*)'\\,|data-mpvid=\\\"([^\\&\\\"]+)/\"),$ytempnr,\"mid,biz,vid\")){\n" +
        "\t$url=\"https://mp.weixin.qq.com/mp/videoplayer?action=get_mp_video_play_url&__biz=$GLOBALS[biz]&mid=$GLOBALS[mid]&idx=1&vid=$GLOBALS[vid]&f=json\";\n" +
        "\t$json=file_get_contents($url);\n" +
        "\t$url=json_decode($json,1);\n" +
        "\t$this->flash($url[url_info][0][url]);\n" +
        "}\n\n" +
        "$urla=qz(\"mainURL=(http\\:\\/\\/[^<>\\s]+?)\",$this->nr);\n" +
        "if($urla){\n" +
        "  $textarea=redo($urla,$this->secexe);\n" +
        "}\n\nif($vid[1]!=''){\n" +
        "  $vid[1]=str_replace(\"-\",\"/\",$vid[1]);\n" +
        "  $data=getjson(\"http://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid={$vid[1]}&tz=-8&from=000news&url=&idl=32&idlr=32&modifyed=false\");\n" +
        "  $this->flash($data['video']['chapters4'][0]['url'],$data['video']['chapters4'][0]['image']);\n" +
        "}\n\n" +
        "$this->flash(\"http://vod.huanjuyun.com/player/loader.swf?appid={appid[1]}&vid={vid[1]}&appid={appid}&playerid=1&autoPlay=0\",\"aviimg\");//用组织网址作视频地址" +
        "\n\n" +
        "$this->flash()//用flvcd网址的抓取\n\n"+
        "if($jsdata['content']['cnt_html']!=\"\"){\n" +
        "  $textarea=$jsdata['content']['cnt_html'];\n" +
        "  $this->title=$jsdata['content']['title'];\n" +
        "  $this->title2=$jsdata['content']['title2'];\n" +
        "  $this->title3=$jsdata['content']['title3'];\n" +
        "  $this->jianjie=$jsdata['content']['abstract'];\n" +
        "  $this->dateline=$jsdata['content']['alt_time'];\n" +
        "  $this->laiyuan=$jsdata['content']['chlname'];\n" +
        "  if($jsdata[video][0][url]){\n" +
        "     $this->flash($jsdata[video][0][url],$jsdata[video][0][cover]);\n" +
        "  }" +
        "}" +
        "</pre>");
}

function jsdata2(){
    layerOpen("<pre>//列表\n$jsdata=$this->changeurl(\"https://apiparty.xinhuaapp.com/Service/ContentSvr.svc/GetContentDetailByWebApi?AppId={appId}&ProjectId={projectId}&AppKey=&contentId={contentId}&channelType=0\");\n" +
        "if($jsdata!=\"\"){\n" +
        "$this->title=$jsdata['Data']['Detail']['Title'];\n" +
        "$this->dateline=$jsdata['Data']['Detail']['IssueTime'];\n" +
        "$this->flash=$jsdata['Data']['Detail']['VodUrl'];\n" +
        "}\n" +
        "$this->yuannr=$this->changeurl(\"https://xinhuaapp-img.oss-cn-hangzhou.aliyuncs.com/caiyunnan/content/\".substr($urlparams['contentId'],-3,3).\"/{contentId}.js?r=637293176762298322\");\n" +
        "\n\n" +
        "$jsdata=$this->changeurl(\"https://apiparty.xinhuaapp.com/Service/IndexSvr.svc/GetIndexPageByWebApi?appId={appId}&styleId=0&projectId={projectId}&pageNo=1\");\n" +
        "\n\n\n\n//请先在【列表页匹配正则】配置捕获tojsdata的规则:" +
        "if(is_array($jsdata)&&count($jsdata)>0){\n" +
        "  $nn22=array();\n" +
        "  for($i=0;$i&lt;count($jsdata);$i++){\n" +
        "     $t=array();\n" +
        "     $t['url']=$jsdata[$i]['url'];\n" +
        "     $t['title']=$jsdata[$i]['title'];\n" +
        "     $nn22[]=$t;\n" +
        "  }\n" +
        "}" +
        "\n\n\n\n" +
        "if($jsdata!=\"\"){\n" +
        " $nn22=array();\n" +
        "  for($i=0;$i&lt;count($jsdata['Data']['IndexContent']);$i++){\n" +
        "     $t=array();\n" +
        "     $t['url']=$jsdata['Data']['IndexContent'][$i]['LinkUrl'];\n" +
        "     $t['title']=$jsdata['Data']['IndexContent'][$i]['Title'];\n" +
        "     $nn22[]=$t;\n" +
        "  }\n" +
        "}"+
        "\n\n\n\n//正文的\n$jsdata=$this->changeurl(\"http://jk2.toutiaohc.com/interface/newsApi.ashx?action=NewsInfo&guid={guid}&sign=1&STiD=0&classify=1&_=1595210670656\");\n" +
        "if($jsdata!=\"\"){\n" +
        " $this->textarea=base64_decode($jsdata['Content']);\n" +
        " $this->yuannr=$this->textarea;\n" +
        " $this->title=base64_decode($jsdata['Title']);\n" +
        " $this->dateline=base64_decode($jsdata['CreateTime']);\n" +
        "}\n\n\n\n" +
        "if($jsdata['initArticleListData']){\n" +
        "  $nn22=array();\n" +
        "  for($i=0;$i&lt;count($jsdata['initArticleListData']);$i++){\n" +
        "     $t=array();\n" +
        "     $t['url']=$jsdata['initArticleListData'][$i]['url'];\n" +
        "     $t['title']=$jsdata['initArticleListData'][$i]['title'];\n" +
        "     $nn22[]=$t;\n" +
        "  }\n" +
        "}\n**如果是json页面可以直接用$this方法取得jsdata(由zqnewbase的isjson方法产生)：\nif($this->jsdata['data'][0]['title']){\n" +
        "\t$nn22=array();\n" +
        "\tfor($i=0;$i&lt;count($this->;jsdata['data']);$i++){\n" +
        "     $t=array();\n" +
        "     $t['url']=$this->jsdata['data'][$i]['url'];\n" +
        "     $t['title']=$this->jsdata['data'][$i]['title'];\n" +
        "     $nn22[]=$t;\n" +
        "\t}\n" +
        "}" +
        "\r\n" +
        "\r\n**在这里如果要保存跳转页的textarea/title/laiyuan，请用$this->redo，不用redo\r\n\r\n" +
        "if(preg_match(\"/\\/t\\/([0-9]+)/\",$this->url,$nn)){\n" +
        "   $this->redo(\"http://appapi.joyme.com/web/appoint?platform=0&referer=&uri=topic%2Fdetail&id={$nn[1]}&topic_key=&callback=__jp2\");\n" +
        "}</pre>");
}

function nn8888(){
    layerOpen(":nn8888(\"(http\:\\/\\/[^<>]*?\\/[^<>]+\\/[0-9a-z_]+?).*(\\.s?html)\",\"2\",\"\\\\1\",\"-%\")\n\nwindow\\.INIT_DETAIL_CONTENT\\s+=\\s*(\\{.*\\})\\s+<\/script>:tojsdata //:tojsdata不要写成jsdata,注意：前面没有反斜杠\n\n");
}

function pqtext(){
    layerOpen("span.inner->text(\"[img]http:\".preg_replace(\"/^.*url\\((.*)\\);/\",\"\\\\1\",pq($aSstrs)->attr(\"style\")).\"[/img]\")\r\n\r\nvideo->attr(\"src\"):nn44\r\n")
}

function layerOpen(str){
    layer.open({
        type: 1,
        skin: 'layui-layer-rim', //加上边框
        area: ['820px', '240px'], //宽高
        content:str
    });
}

function getpython(){
    $.get("http://120.77.245.205/python/getpythonsource.php?host="+$("#this_host").val()+"&r="+Math.random(),[],function(data){
        if(data['source']==""){
            $.get("/python/geturl.py",[],function(text){
                text=text.replace(/Geturl\(\".*?\",\".*?\"\)/,"Geturl(\""+decodeURIComponent($("#this_url").val())+"\",\""+$("#this_host").val()+"\")");
                $("#python").val(text);
                $.post("/python/createpythonfile.php",{'source':text,'host':$("#this_host").val()},function(data){
                    if(data.code==1){
                        layer.tips('写入成功!', '#python_tis');
                    }else{
                        layer.tips('<div style="text-align: left">调用方法示范:<br>if(preg_match("/\\\/video\\\/([^\/]*)$/Uisx",$this->url,$nn)){<br>    \$this->pythongeturl();<br>}</div>', '#python_tis',{tips: [1, '#3595CC'],time: 10000,area: ['500px', '100px']});
                    }
                },"json")
            },"text");
        }else{
            $("#python").val(data['source']);
            $.post("/python/createpythonfile.php",{'source':data['source'],'host':$("#this_host").val()},function(data){
                if(data.code==1){
                    layer.tips('写入成功!', '#python_tis');
                }else{
                    layer.tips('<div style="text-align: left">本地文件已经存在<p>如要覆盖，请删除原文件再重复操作来写入！只能通过ftp上传py文件。<p>调用方法示范:<br>if(preg_match("/\\\/video\\\/([^\/]*)$/Uisx",$this->url,$nn)){<br>    \$this->pythongeturl();<br>}</div>', '#python_tis',{tips: [1, '#3595CC'],time: 10000,area: ['500px', '200px']});
                }
            },"json")
        }
    },"json");
}

function puhuo(){
    window.open("https://collect8.longsunhd.com/collect/reset/puhuo.php?url="+encodeURIComponent($("#s_url").val()));
}

$(document).on("click", "#deletecache", function () {
    $.ajax({
        type: 'post',
        async: true,//true是异步，false是同步
        timeout: 20000,//20秒
        url: "/collect/index.php?action=deletecache", //"?rn="+Math.random(),  //网址请以/开头否则可能不带cookies过去
        data: {cacheid:$("#cacheid").text()},  //$("form").serialize()
        dataType: "json",//html,text,json,jsonp,excel,script
        success: function (data) {
            $("#cacheid").text("")
            $("#yan").text("")
            layer.msg(data.msg);
            return false;
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            debugger;
        }
    });
});
$(document).on("click", "#savecookie", function () {
    $.ajax({
        type: 'post',
        async: true,//true是异步，false是同步
        timeout: 20000,//20秒
        url: "/collect/index.php?action=savecookie&XDEBUG_SESSION_START=54325", //"?rn="+Math.random(),  //网址请以/开头否则可能不带cookies过去
        data: {cookie:$("#cookie").val(),host:$("#this_host").val(),s_url:$("#s_url").val()},  //$("form").serialize()
        dataType: "json",//html,text,json,jsonp,excel,script
        success: function (data) {
            layer.msg(data.msg);
            return false;
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            return false;
        }
    });
    return false;
});


$(document).on("click", "#cacheid", function () {
    if ($("#sourceWin").hasClass("height_suoxiao")) {
        $("dd").removeClass("height_suoxiao");
        $("#viewresult dd,#peizhi dd").hide();
        $("#sourceWin").addClass("height_zankai")
        $("#sourceWin").show();
        $("#yan").css("height", "800px");
    }else{
        $("dd").removeClass("height_zankai");
        $("#viewresult dd,#peizhi dd").show();
        $("#sourceWin").addClass("height_suoxiao")
        $("#yan").css("height", "200px");
    }
});

